package com.File;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

public class MainFile {
    private static final String ROOT_PATH = "C:\\Users\\__Fy\\Desktop\\00 教育实习\\00 作业";
    private static final String OLD_ROOT_PATH = ROOT_PATH + "\\2010 05\\";

    public static void main(String[] args) throws IOException {
        String xml = "I like you!\n";
        byte[] bytesXml = xml.getBytes(StandardCharsets.UTF_8);
        OutputStream os = new FileOutputStream("C:\\Users\\__Fy\\Desktop\\IDM\\text.txt");
        for (int i = 0; i < 10; i++) {
            os.write(bytesXml);
            os.flush();
        }
        os.close();

        File file = new File(OLD_ROOT_PATH);
        File[] listDirect = file.listFiles(File::isDirectory);
        assert listDirect != null;
        for (File direct : listDirect) {
            String oldName = direct.getName();
            File[] listFile = direct.listFiles(File::isFile);
            String newName = oldName.length() == 1 ? "0" + oldName : oldName;
            assert listFile != null;
            if (listFile.length > 0) listFile[0].renameTo(new File(OLD_ROOT_PATH + "00 作业汇总" + "\\" + newName + ".py"));

        }
    }
}
